package com.xuecheng.media.api;

import com.alibaba.nacos.common.utils.StringUtils;
import com.xuecheng.execption.XueChengPlusException;
import com.xuecheng.media.model.po.MediaFiles;
import com.xuecheng.media.service.MediaFilesService;
import com.xuecheng.model.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 小班哥
 * @version 1.0
 * @date 2023/4/16 18:05
 * @description ThisClassExplain
 */
@Api(value = "媒资文件管理接口",tags = "媒资文件管理接口")
@RestController
@RequestMapping("/open")
public class MediaOpenController {

    @Autowired
    private MediaFilesService mediaFilesService;

    @ApiOperation("预览文件")
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable String mediaId){
        MediaFiles mediaFiles = mediaFilesService.GetMediaFilesByID(mediaId);
        String url = mediaFiles.getUrl();
        System.out.println(url);
        if (mediaFiles == null || StringUtils.isEmpty(url)){
            XueChengPlusException.cate("视频还未进行转码,播放失败!");
        }
        return RestResponse.success(url);
    }

}
